<?php  session_start();
if ($_SESSION['MM_Username']){
require("../templates/comun.php"); ?>
<?php

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
   unset($_SESSION['Administrador']);

  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
/*****/

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rs_enviomail = 25;
$pageNum_rs_enviomail = 0;
if (isset($_GET['pageNum_rs_enviomail'])) {
  $pageNum_rs_enviomail = $_GET['pageNum_rs_enviomail'];
}
$startRow_rs_enviomail = $pageNum_rs_enviomail * $maxRows_rs_enviomail;
$conexion=Obtener_Conexion();

//mysql_select_db($database_cnx_pizzeta, $cnx_pizzeta);
$query_rs_maxid="Select Max(codigo_art) as Id from swpr_codigossugeridos";
//$rs_maxid=mysql_query($query_rs_maxid,$cnx_pizzeta) or die (mysql_erros());
$rs_maxid=pg_query($conexion,$query_rs_maxid)  or die ("Error linea: 52 - $query_rs_maxid");


if($row_rs_maxid=pg_fetch_assoc($rs_maxid)){
   $maxid=$row_rs_maxid[Id]+1;
}else{
   $maxid=999;
}
$query_rs_enviomail = "SELECT * FROM swpr_codigossugeridos ORDER BY cs_status,cs_fecha DESC ";
$query_limit_rs_enviomail = sprintf("%s LIMIT %d OFFSET %d ", $query_rs_enviomail,  $maxRows_rs_enviomail,$startRow_rs_enviomail);
$rs_enviomail = pg_query($conexion,$query_limit_rs_enviomail) or die("Error linea 26 - $query_limit_rs_enviomail");
$row_rs_enviomail = pg_fetch_assoc($rs_enviomail);
//echo $query_limit_rs_enviomail; 
if (isset($_GET['totalRows_rs_enviomail'])) {
  $totalRows_rs_enviomail = $_GET['totalRows_rs_enviomail'];
} else {
  $all_rs_enviomail = pg_query($query_rs_enviomail);
  $totalRows_rs_enviomail = pg_num_rows($all_rs_enviomail);
}
$totalPages_rs_enviomail = ceil($totalRows_rs_enviomail/$maxRows_rs_enviomail)-1;

$queryString_rs_enviomail = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rs_enviomail") == false && 
        stristr($param, "totalRows_rs_enviomail") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rs_enviomail = "&" . htmlentities(implode("&", $newParams));
  }
}
   
	
	
 //echo $creado."|".$insertSQL;
$queryString_rs_enviomail = sprintf("&totalRows_rs_enviomail=%d%s", $totalRows_rs_enviomail, $queryString_rs_enviomail);
?>
<style type="text/css">
<!--
.style2 {font-size: 12}
-->
</style>

<div style="padding: 1px; background-color: rgb(250, 222, 116);"><span class="EBDSTYLE_1">Listado de Codigos Sugeridos</span></div>
<table border="0" width="50%" align="center">
  <tr>
    <td width="23%" align="center"><?php if ($pageNum_rs_enviomail > 0) { // Show if not first page ?>
          <a href="#" class="style10"  onclick="Go('<?php printf("%s?pageNum_rs_enviomail=%d%s", $currentPage, 0, $queryString_rs_enviomail); ?>');return false;"><img src="First.gif" border=0></a>
          <?php } // Show if not first page ?>    </td>
    <td width="31%" align="center"><?php if ($pageNum_rs_enviomail > 0) { // Show if not first page ?>
          <a href="#" class="style10"  onclick="Go('<?php printf("%s?pageNum_rs_enviomail=%d%s", $currentPage, max(0, $pageNum_rs_enviomail - 1), $queryString_rs_enviomail); ?>');return false;"><img src="Previous.gif" border=0></a>
          <?php } // Show if not first page ?>    </td>
    <td width="23%" align="center"><?php if ($pageNum_rs_enviomail < $totalPages_rs_enviomail) { // Show if not last page ?>
          <a href="#" class="style10"  onclick="Go('<?php printf("%s?pageNum_rs_enviomail=%d%s", $currentPage, min($totalPages_rs_enviomail, $pageNum_rs_enviomail + 1), $queryString_rs_enviomail); ?>');return false;"><img src="Next.gif" border=0></a>
          <?php } // Show if not last page ?>    </td>
    <td width="23%" align="center"><?php if ($pageNum_rs_enviomail < $totalPages_rs_enviomail) { // Show if not last page ?>
          <a href="#" class="style10"  onclick="Go('<?php printf("%s?pageNum_rs_enviomail=%d%s", $currentPage, $totalPages_rs_enviomail, $queryString_rs_enviomail); ?>');return false;"><img src="Last.gif" border=0></a>
          <?php } // Show if not last page ?>    </td>
  </tr>
</table>
<span class="style2">Registros <?php echo ($startRow_rs_enviomail + 1) ?> a <?php echo min($startRow_rs_enviomail + $maxRows_rs_enviomail, $totalRows_rs_enviomail) ?> de <?php echo $totalRows_rs_enviomail ?></span>
<table class="formularioeditable"   border="0" CELLSPACING="0" CELLPADDING="2" width="90%">
<tr>

	<td colspan="7" align="right"><a href="<?php echo $logoutAction ?> "  >Salir</a></td> 
  </tr>
  <tr style="background-color: rgb(182, 209, 251);">
    <th class="formularioeditable">Codigo</th>
    <th class="formularioeditable">Aplicacion</th>
    <th class="formularioeditable">Marca</th>
    <th class="formularioeditable">Cliente</th>
    <th class="formularioeditable">Fecha registro</th>
    <th class="formularioeditable">Status</th>
	<th class="formularioeditable"></th>
  </tr>
<?php $cc=0;
     do { ?><?php $cc++;if(($cc % 2)==0) {$bg="#CCCCCC"; }else{ $bg="#FFFFFF";}?>
    <tr bgcolor="<?php echo $bg;?>"> 
      
	  <td class="formularioeditable"><a href="act_codigossugeridos.php?codigo_art=<?php echo $row_rs_enviomail['codigo_art']; ?>" class="formularioeditable"  ><?php echo $row_rs_enviomail['codigo_art']; ?></a></td>
      <td class="formularioeditable"><?php echo $row_rs_enviomail['cs_aplicacion']; ?></td>
      <td class="formularioeditable"><?php echo $row_rs_enviomail['cs_marca']; ?></td>
      <td class="formularioeditable"><?php echo $row_rs_enviomail['cs_numcte']; ?></td>
       <td class="formularioeditable"><?php echo $row_rs_enviomail['cs_fecha']; ?></td>
      <td class="formularioeditable"><?php echo $row_rs_enviomail['cs_status']; ?></td>
      <td></td>
<!-- 	  <td class="formularioeditable"><a href="#" onclick="borrarEnvMail(<?php echo $row_rs_enviomail['IdMail']; ?>); return false;" >suprimir</a></td> -->
    </tr>
    <?php } while ($row_rs_enviomail = pg_fetch_assoc($rs_enviomail)); ?>
</table>

<?php

$creado = pg_affected_rows($res);
	Desconectar($conexion);
}else{header("Location: index.php" ); }
?>
